package cn.edu.ruc.cloudcomputing.book.zookeeperTest;

import java.io.IOException;
import java.util.List;

import org.apache.zookeeper.KeeperException;
/**
 * 删除组目录下所有的成员
 * @author JunJie.Wang
 *
 */
public class DelGroup extends ZookeeperInstance {

	public void delete(String groupPath) throws KeeperException, InterruptedException{
		List<String> children = zk.getChildren(groupPath, false);
		
		//如果不空，则进行删除操作
		if(!children.isEmpty()){
			//删除所有的子节点
			for(String child:children){
				zk.delete(groupPath+"/"+child, -1);
			}
		}
		
		//删除组目录节点
		zk.delete(groupPath, -1);
	}
	
	public static void main(String[] args) throws IOException, KeeperException, InterruptedException{
		DelGroup dg = new DelGroup();
		dg.createZKInstance();
		dg.delete("/ZKGroup08030002");
		dg.ZKclose();
	}
	
}
